package chart;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

// 折线图
public class LineChartDemo extends Application {
	private Pane root = new Pane();
	private NumberAxis x = new NumberAxis("x轴", 0, 100, 10);
	private NumberAxis y = new NumberAxis("y轴", 0, 100, 10);
	private LineChart<Number, Number> lc = new LineChart<>(x, y);
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
		
		lc.setCreateSymbols(true);		// 折线的折点是否显示
//		lc.setVerticalGridLinesVisible(false);		// 线是否可视
//		lc.setHorizontalGridLinesVisible(false);
		lc.setStyle("-fx-background-color: lightgreen");
		lc.setPrefSize(400, 400);
		
		XYChart.Data<Number, Number> data1 = new XYChart.Data<>(10, 10);
		XYChart.Data<Number, Number> data2 = new XYChart.Data<>(40, 40);
		XYChart.Data<Number, Number> data3 = new XYChart.Data<>(70, 70);
		XYChart.Data<Number, Number> data4 = new XYChart.Data<>(10, 30);
		XYChart.Data<Number, Number> data5 = new XYChart.Data<>(30, 80);
		XYChart.Data<Number, Number> data6 = new XYChart.Data<>(70, 20);
		
		XYChart.Series<Number, Number> line1 = new XYChart.Series<>();
		line1.setName("Line1");
		line1.getData().add(data1);
		line1.getData().add(data2);
		line1.getData().add(data3);
		
		XYChart.Series<Number, Number> line2 = new XYChart.Series<>();
		line2.setName("Line2");
		line2.getData().add(data4);
		line2.getData().add(data5);
		line2.getData().add(data6);
		
		lc.getData().add(line1);
		lc.getData().add(line2);
		root.getChildren().add(lc);
		
		Scene scene = new Scene(root, 400, 400);
		stage.setScene(scene);
		stage.show();
	}

}
